<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="input1" value="">+ <input type="text" id="input2" value="">=
    <span id="span"></span><br>
    <input type="button" value="相加" onclick="add()">
    <script>
        function add()
        {
            var a =parseInt(document.getElementById("input1").value) 
            //console.log(a)
            //获取数据1 parseInt()方法使字符串变成整型
            var b = parseInt(document.getElementById("input2").value)
            //console.log(b)
            //获取数据2
            var sum = a + b;
            //console.log(sum)
            //和
            //console.log(typeof(a))
            //判断数据类型 innerHTML inneText
            document.getElementById("span").innerHTML=sum
            //将结果渲染到浏览器上
        }
    </script>
    <!-- 加法运算 -->
</body>
</html>